Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prioritized route proof of concept #224

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

arlowhite
Copy link

@arlowhite arlowhite commented Sep 27, 2024

Proof of concept and proposal for prioritized requests.
Feature request issue #223

This approach examines HTTP.Request before spawning a thread in the :default threadpool. If condition is true, it handles the request in the Main thread, which is a reserved thread in the :interactive pool if you launched server with -t auto,1

Proposed API

new kwarg on serve()
is_prioritized: (req::HTTP.Request) -> bool
Affects parallel mode; if the function returns true, the request will be handled in the current main thread instead of spawning a thread from the :default threadpool. This allows the server to handle requests when all :default threads are busy. The main use case is to allow health checks to respond when all worker threads are busy. For this to work, you should launch Julia with at least one dedicated interactive thread. e.g. --threads=auto,1, see Julia multi-threading documentation.

    serveparallel(
        is_prioritized = (req::HTTP.Request) -> req.target == "/health"
    )

TODO

  • acceptance of implementation and config
  • cleanup PR
  • documentation
  • test

src/core.jl Outdated
req::HTTP.Request = stream.message

# if prioritized path
if (req.target == "/health")
Copy link
Author

@arlowhite arlowhite Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the magic is here

@arlowhite
Copy link
Author

arlowhite commented Sep 27, 2024

This is just a draft for feedback on this approach, I realize I need to remove all the debug/info statements. If you like this implementation, let me know and I'll cleanup the PR and go through the TODO tasks.

@arlowhite arlowhite force-pushed the prioritized-request-poc branch from a22d8f3 to d4bb501 Compare September 27, 2024 04:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant